﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>经销商编辑</title>
    <script src="/Apm/js/CMSEdit.js"></script>
    <style>
        
    </style>
</head>
<body>
    <div class="page">
        <div id="title" class="title">

        </div>
        
        <div class="layui-form layui-form-pane edit-form">
            
            <div class="layui-form-item">
                <label class="layui-form-label">经销商</label>
                <div class="layui-input-block">
                    <input id="Name" type="text" name="Name" required lay-verify="required" placeholder="请输入经销商名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">负责人</label>
                <div class="layui-input-block">
                    <input id="Lxr" type="text" name="Lxr" required lay-verify="required" placeholder="请输入经销商负责人" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话</label>
                <div class="layui-input-block">
                    <input id="LxrPhone" type="text" name="LxrPhone" required lay-verify="required" placeholder="请输入经销商电话" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input id="Address" type="text" name="Address" required lay-verify="required" placeholder="请输入经销商地址" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电子邮件</label>
                <div class="layui-input-block">
                    <input id="Email" type="text" name="Email" lay-verify="email" placeholder="请输入电子邮件" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开户银行</label>
                <div class="layui-input-block">
                    <input id="Khbank" type="text" name="Khbank"  placeholder="请输入开户银行" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" pane>
                <label class="layui-form-label">启用</label>
                <div class="layui-input-block">
                    <input id="State" type="checkbox" name="State" lay-text="是|否" value="1" checked lay-skin="switch">
                </div>
            </div>
            

            <button id="submit" lay-submit lay-filter="submit" style="display:none;"></button>
        </div>

        <div class="edit-submit">
            <button id="truebutton" class="layui-btn layui-btn-lg">提交</button>
        </div>
    </div>
</body>
</html>
<script>
    layui.use(['layer', 'form', 'upload'], function () {
        var layer = layui.layer,
            form = layui.form,
            upload = layui.upload;

        var type = MyPublic.getUrlParam('type');
        var id = MyPublic.getUrlParam('id');

        switch (type) {
            case 'add':
                $("#title").html('添加经销商');

                break;
            case 'edit':
                $("#title").html('编辑经销商');
                BindDataModel(id)
                break;
        }
        
        $("#truebutton").click(function () {
            $("#submit").click();
        })

        

        //添加或修改
        form.on('submit(submit)', function (data) {
            //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            var json = data.field;
            
            switch (type) {
                case 'add':
                    ajaxpost({
                        url: 'api/FriendFlower/CustomerCreate?Token=' + MyPublic.getToken(),
                        data: json,
                        success: function (data) {
                            data = JSON.parse(data);
                            if (data.code === "10000") {
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                            else {
                                layer.msg(data.msg);
                            }
                        }
                    })

                    break;
                case 'edit':
                    json.Guid = id;
                    ajaxpost({
                        url: 'api/FriendFlower/CustomerUpdate?Token=' + MyPublic.getToken(),
                        data: json,
                        success: function (data) {
                            data = JSON.parse(data);
                            if (data.code === "10001") {
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                            else {
                                layer.msg(data.msg);
                            }
                        }
                    })
                    break;
            }

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


    });
    
    function BindDataModel(guid) {
        layui.use(['layer', 'form'], function () {
            var layer = layui.layer,
                form = layui.form;

            ajaxget({
                url: 'api/FriendFlowerPublic/GetCustomerModel?Guid=' + guid,
                success: function (data) {
                    $("#Name").val(data.Name);
                    $("#Address").val(data.Address);
                    $("#Lxr").val(data.Lxr);
                    $("#LxrPhone").val(data.LxrPhone);
                    $("#Khbank").val(data.Khbank);
                    $("#Email").val(data.Email);
                    if (data.State === 1) {
                        $("#State").attr('checked', true);
                    }
                    else {
                        $("#State").attr('checked', false);
                    }
                    form.render('checkbox');
                    
                    
                }
            })
        });
    }
    
</script>